const centerLat = 35.126643
const centerLng = 111.006993
const defautZommLevel = 10

// 计算平均经度和平均纬度
function calculateCenter(coordinates) {
  if (coordinates.length === 0) {
    return null // 如果坐标列表为空，返回 null
  }

  let sumLatitude = 0
  let sumLongitude = 0

  for (const coordinate of coordinates) {
    sumLatitude += coordinate.latitude
    sumLongitude += coordinate.longitude
  }

  const averageLatitude = sumLatitude / coordinates.length
  const averageLongitude = sumLongitude / coordinates.length

  return { latitude: averageLatitude, longitude: averageLongitude }
}

// 方法定义 lat,lng
function getDistance(lat1, lng1, lat2, lng2) {
  var radLat1 = lat1 * Math.PI / 180.0
  var radLat2 = lat2 * Math.PI / 180.0
  var a = radLat1 - radLat2
  var b = lng1 * Math.PI / 180.0 - lng2 * Math.PI / 180.0
  var s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
    Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)))
  s = s * 6378.137// EARTH_RADIUS;
  s = Math.round(s * 10000) / 10000
  return s * 1000
}

const yanhuPolygon =
  [
    [111.028397, 34.91406],
    [111.021168, 34.905602],
    [111.017633, 34.900331],
    [111.018555, 34.897233],
    [111.017547, 34.896507],
    [111.008776, 34.898034],
    [111.00614, 34.899424],
    [110.99827, 34.896467],
    [110.991334, 34.892933],
    [110.984643, 34.886756],
    [110.983807, 34.886422],
    [110.970047, 34.885766],
    [110.968155, 34.884795],
    [110.962319, 34.876765],
    [110.96146, 34.876107],
    [110.946585, 34.874546],
    [110.94533, 34.874326],
    [110.93781, 34.865533],
    [110.937534, 34.864588],
    [110.92971, 34.864406],
    [110.927829, 34.864015],
    [110.924754, 34.859135],
    [110.923188, 34.857331],
    [110.909618, 34.847653],
    [110.908564, 34.846912],
    [110.900554, 34.845514],
    [110.899577, 34.844893],
    [110.891661, 34.835302],
    [110.890196, 34.834391],
    [110.882819, 34.833291],
    [110.881431, 34.833352],
    [110.865702, 34.838428],
    [110.863201, 34.838555],
    [110.857706, 34.836475],
    [110.854642, 34.835518],
    [110.849933, 34.83651],
    [110.849095, 34.836576],
    [110.844507, 34.835114],
    [110.842831, 34.833861],
    [110.838755, 34.835778],
    [110.836843, 34.835563],
    [110.824576, 34.8322],
    [110.821513, 34.830441],
    [110.810409, 34.818694],
    [110.809091, 34.818534],
    [110.796819, 34.821752],
    [110.7939, 34.821257],
    [110.789821, 34.823907],
    [110.788502, 34.824089],
    [110.779471, 34.823899],
    [110.778358, 34.823844],
    [110.771812, 34.821009],
    [110.769381, 34.818852],
    [110.765058, 34.831297],
    [110.764364, 34.832562],
    [110.755548, 34.843471],
    [110.754328, 34.846629],
    [110.753805, 34.853225],
    [110.753511, 34.855643],
    [110.749575, 34.862031],
    [110.749079, 34.864802],
    [110.75255, 34.871006],
    [110.752505, 34.87192],
    [110.739588, 34.885967],
    [110.739439, 34.886455],
    [110.740236, 34.890116],
    [110.741552, 34.894555],
    [110.748437, 34.898911],
    [110.749645, 34.900009],
    [110.750691, 34.90496],
    [110.752761, 34.910176],
    [110.756322, 34.912055],
    [110.763533, 34.91283],
    [110.770213, 34.91108],
    [110.771052, 34.911483],
    [110.771064, 34.925718],
    [110.77007, 34.926493],
    [110.766291, 34.92629],
    [110.760773, 34.925077],
    [110.749329, 34.926815],
    [110.748078, 34.928531],
    [110.7476, 34.941947],
    [110.743177, 34.956628],
    [110.741524, 34.962847],
    [110.747718, 34.974922],
    [110.749983, 34.977575],
    [110.753549, 34.97908],
    [110.757903, 34.981223],
    [110.764921, 34.986918],
    [110.765975, 34.989234],
    [110.765259, 34.99213],
    [110.758872, 34.999277],
    [110.757827, 35.002084],
    [110.759727, 35.018338],
    [110.760583, 35.019543],
    [110.763194, 35.021864],
    [110.768974, 35.022522],
    [110.773127, 35.017629],
    [110.783001, 35.014773],
    [110.786037, 35.016559],
    [110.789136, 35.025884],
    [110.798246, 35.030787],
    [110.800654, 35.031871],
    [110.803393, 35.031623],
    [110.807533, 35.029366],
    [110.821938, 35.028781],
    [110.827193, 35.028685],
    [110.834522, 35.032384],
    [110.838884, 35.041727],
    [110.84233, 35.043757],
    [110.86002, 35.043839],
    [110.866536, 35.046004],
    [110.876289, 35.054822],
    [110.881058, 35.055293],
    [110.885057, 35.05623],
    [110.892172, 35.060315],
    [110.895846, 35.061671],
    [110.899579, 35.059957],
    [110.904855, 35.05355],
    [110.915455, 35.049948],
    [110.921047, 35.053685],
    [110.922427, 35.054607],
    [110.92253, 35.06156],
    [110.919668, 35.06729],
    [110.909778, 35.070123],
    [110.901502, 35.076704],
    [110.902206, 35.096376],
    [110.901756, 35.098449],
    [110.898321, 35.105882],
    [110.897116, 35.109159],
    [110.894918, 35.110963],
    [110.893819, 35.112176],
    [110.887793, 35.127147],
    [110.886183, 35.131063],
    [110.879296, 35.140483],
    [110.875423, 35.146439],
    [110.875225, 35.15188],
    [110.875736, 35.152972],
    [110.882219, 35.157708],
    [110.882253, 35.159594],
    [110.878018, 35.164539],
    [110.876637, 35.165854],
    [110.860979, 35.176066],
    [110.859341, 35.178151],
    [110.85531, 35.195738],
    [110.854831, 35.196779],
    [110.861012, 35.204378],
    [110.861942, 35.206031],
    [110.874201, 35.209729],
    [110.875398, 35.210455],
    [110.887381, 35.222413],
    [110.888312, 35.223776],
    [110.894032, 35.237719],
    [110.89435, 35.239019],
    [110.891916, 35.24385],
    [110.887963, 35.244509],
    [110.887803, 35.249246],
    [110.888811, 35.255814],
    [110.895731, 35.263084],
    [110.901054, 35.27043],
    [110.909049, 35.274725],
    [110.912259, 35.276328],
    [110.923077, 35.273559],
    [110.925198, 35.27381],
    [110.923451, 35.286041],
    [110.923588, 35.287056],
    [110.932844, 35.290434],
    [110.939167, 35.293907],
    [110.939, 35.300276],
    [110.940622, 35.301344],
    [110.945282, 35.303248],
    [110.949697, 35.303558],
    [110.955446, 35.299377],
    [110.956985, 35.29936],
    [110.958363, 35.301978],
    [110.958876, 35.303235],
    [110.957904, 35.310721],
    [110.955627, 35.315126],
    [110.958014, 35.317481],
    [110.966408, 35.320483],
    [110.975189, 35.329648],
    [110.981322, 35.334428],
    [110.985853, 35.346154],
    [110.98986, 35.357338],
    [110.998365, 35.370922],
    [110.999422, 35.371195],
    [111.00377, 35.370177],
    [111.003921, 35.369703],
    [111.002566, 35.36848],
    [110.999935, 35.364147],
    [111.002482, 35.35785],
    [111.004915, 35.355195],
    [111.010229, 35.355289],
    [111.01071, 35.3552],
    [111.010432, 35.35464],
    [111.01032, 35.353595],
    [111.012137, 35.353495],
    [111.014935, 35.35258],
    [111.015862, 35.355261],
    [111.017234, 35.355537],
    [111.018716, 35.355027],
    [111.020921, 35.353278],
    [111.02498, 35.354091],
    [111.025424, 35.353926],
    [111.024539, 35.352111],
    [111.024349, 35.351609],
    [111.027869, 35.350166],
    [111.028276, 35.349728],
    [111.025868, 35.349601],
    [111.025034, 35.349281],
    [111.025866, 35.346197],
    [111.026996, 35.345126],
    [111.028905, 35.346644],
    [111.030276, 35.345528],
    [111.033811, 35.339577],
    [111.035608, 35.33875],
    [111.044442, 35.338361],
    [111.04781, 35.336008],
    [111.050658, 35.330394],
    [111.049352, 35.329287],
    [111.050304, 35.32699],
    [111.052311, 35.325473],
    [111.053143, 35.325074],
    [111.050376, 35.324789],
    [111.04971, 35.32453],
    [111.050833, 35.315637],
    [111.050885, 35.3106],
    [111.054544, 35.303194],
    [111.054746, 35.300562],
    [111.058758, 35.297361],
    [111.059054, 35.296999],
    [111.065859, 35.297417],
    [111.066543, 35.297417],
    [111.070403, 35.291809],
    [111.071418, 35.2901],
    [111.077754, 35.288116],
    [111.079692, 35.286405],
    [111.081037, 35.282003],
    [111.082305, 35.280971],
    [111.081961, 35.278533],
    [111.082131, 35.277501],
    [111.077669, 35.274391],
    [111.077179, 35.273967],
    [111.079078, 35.27105],
    [111.079059, 35.270748],
    [111.07517, 35.268348],
    [111.074662, 35.268144],
    [111.072853, 35.268641],
    [111.072171, 35.269926],
    [111.06358, 35.269092],
    [111.062267, 35.26841],
    [111.062654, 35.266415],
    [111.062653, 35.265689],
    [111.04703, 35.258427],
    [111.046216, 35.257964],
    [111.046243, 35.256641],
    [111.046271, 35.256164],
    [111.044236, 35.255276],
    [111.0437, 35.254632],
    [111.045188, 35.251432],
    [111.045358, 35.250851],
    [111.043845, 35.249392],
    [111.043576, 35.248772],
    [111.043724, 35.247993],
    [111.04438, 35.247118],
    [111.047458, 35.247722],
    [111.047781, 35.247465],
    [111.046411, 35.24378],
    [111.046651, 35.243455],
    [111.049461, 35.243627],
    [111.04971, 35.243462],
    [111.053421, 35.237692],
    [111.060338, 35.234081],
    [111.061215, 35.233599],
    [111.06136, 35.23068],
    [111.062486, 35.229782],
    [111.06497, 35.229642],
    [111.066483, 35.228252],
    [111.066038, 35.225091],
    [111.065409, 35.223972],
    [111.067357, 35.21301],
    [111.067059, 35.210167],
    [111.070135, 35.203441],
    [111.07043, 35.202488],
    [111.0691, 35.201126],
    [111.069247, 35.200718],
    [111.070908, 35.200523],
    [111.071683, 35.199798],
    [111.073294, 35.195762],
    [111.073588, 35.195028],
    [111.071834, 35.193643],
    [111.071538, 35.193242],
    [111.074413, 35.189267],
    [111.074754, 35.189063],
    [111.074041, 35.185622],
    [111.073947, 35.184723],
    [111.075403, 35.182841],
    [111.075532, 35.182281],
    [111.074211, 35.180443],
    [111.075867, 35.176286],
    [111.076752, 35.175318],
    [111.078356, 35.17476],
    [111.085915, 35.173961],
    [111.088108, 35.173689],
    [111.094932, 35.178679],
    [111.096793, 35.17889],
    [111.103801, 35.170674],
    [111.103707, 35.168723],
    [111.106871, 35.166634],
    [111.107588, 35.165877],
    [111.106895, 35.157469],
    [111.107151, 35.156153],
    [111.113073, 35.152669],
    [111.113808, 35.151745],
    [111.114189, 35.147828],
    [111.114188, 35.147177],
    [111.112733, 35.146302],
    [111.112621, 35.145259],
    [111.114772, 35.143623],
    [111.110865, 35.139816],
    [111.112814, 35.138136],
    [111.113107, 35.137455],
    [111.112329, 35.133418],
    [111.111058, 35.132345],
    [111.112712, 35.130982],
    [111.112747, 35.130181],
    [111.102299, 35.119446],
    [111.100254, 35.117965],
    [111.105895, 35.113938],
    [111.105857, 35.113038],
    [111.095871, 35.10758],
    [111.095631, 35.106791],
    [111.09794, 35.0991],
    [111.098105, 35.098676],
    [111.101428, 35.096387],
    [111.101649, 35.095956],
    [111.100539, 35.094754],
    [111.100243, 35.094066],
    [111.100316, 35.093896],
    [111.101838, 35.092825],
    [111.10136, 35.089472],
    [111.101286, 35.089116],
    [111.099821, 35.087877],
    [111.0996, 35.087174],
    [111.111477, 35.086294],
    [111.112158, 35.086221],
    [111.116394, 35.088178],
    [111.116674, 35.088246],
    [111.116916, 35.086975],
    [111.117035, 35.086627],
    [111.118616, 35.086893],
    [111.120286, 35.087772],
    [111.121885, 35.084684],
    [111.122325, 35.084464],
    [111.128161, 35.085292],
    [111.12886, 35.085397],
    [111.130566, 35.084388],
    [111.133989, 35.081923],
    [111.13646, 35.082439],
    [111.136855, 35.082438],
    [111.137521, 35.07455],
    [111.139146, 35.074508],
    [111.138124, 35.072711],
    [111.138582, 35.070769],
    [111.134664, 35.065274],
    [111.134561, 35.064514],
    [111.137262, 35.065279],
    [111.137941, 35.065236],
    [111.147474, 35.060021],
    [111.148061, 35.059959],
    [111.147738, 35.058599],
    [111.14837, 35.057841],
    [111.152788, 35.055288],
    [111.15342, 35.054605],
    [111.153967, 35.052683],
    [111.153874, 35.05226],
    [111.152002, 35.051849],
    [111.151928, 35.051622],
    [111.153089, 35.04954],
    [111.152436, 35.048521],
    [111.155821, 35.043452],
    [111.155921, 35.043051],
    [111.156618, 35.043087],
    [111.15696, 35.044212],
    [111.157251, 35.043085],
    [111.157664, 35.042985],
    [111.159904, 35.043916],
    [111.160408, 35.043862],
    [111.161011, 35.042499],
    [111.16099, 35.041357],
    [111.168386, 35.038143],
    [111.180001, 35.031602],
    [111.182051, 35.030083],
    [111.182137, 35.027436],
    [111.182813, 35.026193],
    [111.186895, 35.022822],
    [111.187022, 35.022141],
    [111.186396, 35.021432],
    [111.182123, 35.021114],
    [111.181254, 35.018228],
    [111.18281, 35.016324],
    [111.173374, 35.011667],
    [111.172428, 35.011186],
    [111.160014, 35.00206],
    [111.157847, 35.00029],
    [111.153119, 35.001922],
    [111.150716, 35.002109],
    [111.147708, 34.999079],
    [111.145402, 34.998631],
    [111.145323, 34.992733],
    [111.144338, 34.989587],
    [111.148002, 34.984626],
    [111.147843, 34.98368],
    [111.14487, 34.983001],
    [111.142851, 34.982189],
    [111.139995, 34.979547],
    [111.136863, 34.977611],
    [111.12746, 34.977212],
    [111.125317, 34.975293],
    [111.127429, 34.972709],
    [111.127271, 34.972231],
    [111.121252, 34.965918],
    [111.120767, 34.963934],
    [111.115418, 34.960386],
    [111.11503, 34.960207],
    [111.1126, 34.960309],
    [111.112176, 34.960101],
    [111.117396, 34.955023],
    [111.116742, 34.9541],
    [111.112478, 34.957385],
    [111.111198, 34.957864],
    [111.108202, 34.956434],
    [111.10762, 34.955599],
    [111.101675, 34.955823],
    [111.099354, 34.955406],
    [111.09592, 34.953557],
    [111.094684, 34.95113],
    [111.082927, 34.947289],
    [111.07908, 34.947387],
    [111.064714, 34.932171],
    [111.060937, 34.93067],
    [111.060546, 34.926893],
    [111.059753, 34.925601],
    [111.054394, 34.925251],
    [111.048894, 34.922037],
    [111.045817, 34.922389],
    [111.042668, 34.922184],
    [111.04067, 34.921119],
    [111.039855, 34.918755],
    [111.029428, 34.916313]

  ]

export default {
  centerLat,
  centerLng,
  defautZommLevel,
  calculateCenter,
  yanhuPolygon,
  getDistance
}
